package com.isfto.dao;


import com.isfto.entity.tablepojo.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface FlightInfoDao {
    /**
     * 基础页面信息查询
     * @param page
     * @param pageSize
     * @return
     */
    @Select("select * from showtables limit #{page},#{pageSize}")
    List<FlightInfo> flightInfoAll(@Param("page") Integer page, @Param("pageSize") Integer pageSize);

    //查询变更信息
    @Select("select * from dlye where fide=#{fide}")
    List<Dlye> dlyeInfo(String fide);

    //查询变更时间信息
    @Select("select * from dfme_frtt where fide=#{fide}")
    List<Dlye> frttInfo(String fide);

    @Select("select * from abrs")
    List<ABRS> abrsInfos();

    @Select("select number from abrs where cnnm=#{cnnm}")
    ABRS abrsnumber(String cnnm);

    @Select("select cnnm from abrs where number=#{number}")
    ABRS abrsInfo(String number);
    /**
     * 航班起飞更新时间
     * @param upstartfptt
     * @param startapcd
     * @param bfstartfptt
     * @return
     */
    @Update("update dfoe_dfdl_dflt_arpt1 set startfptt=#{upstartfptt} where startapcd=#{startapcd} and startfptt=#{bfstartfptt}")
    Integer updateInfoStart(@Param("upstartfptt") String upstartfptt,@Param("startapcd") String startapcd,@Param("bfstartfptt") String bfstartfptt);
    /**
     * 航班降落更新时间
     */
    @Update("update dfoe_dfdl_dflt_arpt3 set endfplt=#{upendfplt} where endapcd=#{endapcd} and endfplt=#{bfendfplt}")
    Integer updateInfoEnd(@Param("upendfplt") String upendfplt,@Param("endapcd") String endapcd,@Param("bfendfplt") String bfendfplt);
    /**
     * 基础页面总记录数
     * @return
     */
    @Select("select count(*) from showtables")
    Integer total();

    /**
     * 进港条件查询总记录数
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @Select(" select count(*) from flightInfoEnter where startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt>=#{startfptt} and endfplt<=#{endfplt}")
    Integer flightCount(@Param("startapcd") String startapcd, @Param("endapcd") String endapcd,@Param("startfptt") String startfptt,@Param("endfplt") String endfplt);

    /**
     * 进港条件查询
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @param page
     * @param pageSize
     * @return
     */
    @Select(" select * from flightInfoEnter where startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt>=#{startfptt} and endfplt<=#{endfplt} order by startfptt  limit #{page},#{pageSize}")
    List<FlightInfoDetail> flightInfoDetailEnter(@Param("startapcd") String startapcd, @Param("endapcd") String endapcd, @Param("startfptt") String startfptt, @Param("endfplt") String endfplt, @Param("page") Integer page, @Param("pageSize") Integer pageSize);

    /**
     * 进港航班信息查询
     * @param page
     * @param pageSize
     * @return
     */
    @Select(" select * from flightInfoEnter where startapat=#{startapat} limit #{page},#{pageSize}")
    List<FlightInfoDetail> flightInfoEnter(@Param("page") Integer page,@Param("pageSize") Integer pageSize,@Param("startapat") String startapat);

    /**
     * 进港航班总数
     * @return
     */
    @Select(" select count(*) from flightInfoEnter where startapat=#{startapat}")
    Integer flightInfoEnterCount(String startapat);

    /**
     * 出港航班信息
     * @param page
     * @param pageSize
     * @return
     */
    @Select(" select * from flightInfoOut where endapat=#{endapat} limit #{page},#{pageSize}")
    List<FlightInfoDetail> flightInfoOut(@Param("page") Integer page,@Param("pageSize") Integer pageSize,@Param("endapat") String endapat);

    /**
     * 出港航班总数
     * @return
     */
    @Select(" select count(*) from flightInfoOut where endapat=#{endapat}")
    Integer flightInfoOutCount(String endapat);

    /**
     * 出港条件查询总记录数
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @return
     */
    @Select(" select count(*) from flightInfoOut where startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt>=#{startfptt} and endfplt<=#{endfplt} ")
    Integer flightOutCount(@Param("startapcd") String startapcd, @Param("endapcd") String endapcd,@Param("startfptt") String startfptt,@Param("endfplt") String endfplt);

    /**
     * 出港条件查询
     * @param startapcd
     * @param endapcd
     * @param startfptt
     * @param endfplt
     * @param page
     * @param pageSize
     * @return
     */
    @Select(" select * from flightInfoOut where startapcd=#{startapcd} and endapcd=#{endapcd} and startfptt>=#{startfptt} and endfplt<=#{endfplt} order by startfptt  limit #{page},#{pageSize}")
    List<FlightInfoDetail> flightInfoDetailOut(@Param("startapcd") String startapcd, @Param("endapcd") String endapcd,@Param("startfptt") String startfptt,@Param("endfplt") String endfplt,@Param("page") Integer page,@Param("pageSize") Integer pageSize);

    /**
     * 进港航线信息
     * @return
     */
    @Select("select startapcd as name,count(*) as value from flightinfoenter where startapat=2403 and endapat=2403 group by startapcd")
    List<AirLine> enterAirLine();


    @Select("select count(*) as count from flightinfoenter where startfptt>=#{starttime} and startfptt<=#{endtime} and startapat=#{startapat} and endapat=2403")
    List<AirLine> countAirLine(@Param("starttime") String starttime,@Param("endtime") String endtime,@Param("startapat")String startapat);

    /**
     * 出港航线信息查询
     * @return
     */
    @Select("select endapcd as name,count(*) as value from flightinfoout where startapat=2403 and endapat=2403 group by endapcd")
    List<AirLine> outAirLine();

    @Select("select count(*) as count from flightinfoout where startfptt>=#{starttime} and startfptt<=#{endtime} and endapat=#{endapat}")
    List<AirLine> outcountAirLine(@Param("starttime") String starttime,@Param("endtime") String endtime,@Param("endapat")String endapat);

    @Insert( "insert into tickets(cfno,startapcd,startfptt,endapcd,endfplt,status) values (#{cfno},#{startapcd},#{startfptt},#{endapcd},#{endfplt},#{status})" )
    void bytickets(Tickets tickets);

    @Select( "select *from tickets where status != 0" )
    List<Tickets> gettickets();

    @Update( "update tickets set status=#{status} where id = #{id}" )
    Boolean refundTicket(Integer id,Integer status);
}
